﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ThucThe;
using DieuKhien;

namespace GiaoDien
{
    public partial class QL_VanTai_sua : Form
    {
        public QL_VanTai_sua()
        {
            InitializeComponent();
        }

        VanTai_dieukhien vt_dk = new VanTai_dieukhien();
        VanTai_thucthe vt_tt = new VanTai_thucthe();

        private void btn_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        public void loadVanTai(VanTai_thucthe vt)
        {
            txt_email.Text = vt.Email;
            txt_loaiHinh.Text = vt.LoaiHinh;
            txt_maVT.Text = vt.MaVanTai.ToString();
            txt_maVT.Enabled = false;
            txt_moTa.Text = vt.MoTa;
            txt_tenVT.Text = vt.TenVanTai;
            msktxt_sdt.Text = vt.Sdt;
        }
        private void btn_OK_Click(object sender, EventArgs e)
        {
            try
            {
                vt_tt.TenVanTai = txt_tenVT.Text.Trim();
                vt_tt.Email = txt_email.Text.Trim();
                vt_tt.Sdt = msktxt_sdt.Text.Trim();
                vt_tt.LoaiHinh = txt_loaiHinh.Text;
                vt_tt.MoTa = txt_moTa.Text;

                vt_dk.suaVanTai(vt_tt);
                MessageBox.Show("Sửa thành công");
                this.Close();
                QL frm_ql = new QL();
                frm_ql.Show();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Nhập đầy đủ các trường");
            }
            catch (FormatException)
            {
                MessageBox.Show("Nhập số cho số điện thoại");
            }
        }

        private void btn_reset_Click(object sender, EventArgs e)
        {
            txt_email.Text = "";
            txt_loaiHinh.Text = "";
            txt_moTa.Text = "";
            txt_tenVT.Text = "";
            msktxt_sdt.Text = "";
        }


    }
}
